﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.货号管理.service;

namespace DXApplicationTangche.UC.货号管理
{
    public partial class Form工艺设计 : DevExpress.XtraEditors.XtraForm
    {
        private List<CraftDesignItemDTO> craftDesignItemDTOs = new List<CraftDesignItemDTO>();//工序
        private List<CraftDesignDTO> craftDesignDTOs = new List<CraftDesignDTO>();//与新建工艺设计在知识库中匹配相似的结果
        private Boolean if相似判断 = false;
        public Form工艺设计()
        {
            InitializeComponent();
            this.addCraftDesignItemDTOs();
            this.gridControl工序要求.DataSource = craftDesignItemDTOs;
        }

        private void addCraftDesignItemDTOs()
        {
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("审版", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("调版", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("裁断", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("粘衬", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("车间", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("半成手缝", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("特种", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("成品手缝", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("检查", false));
            craftDesignItemDTOs.Add(new CraftDesignItemDTO("销售", false));
        }
        private void textBox工艺名称_TextChanged(object sender, EventArgs e)
        {
            this.if相似判断 = false;
        }
        private void simpleButton确认_Click(object sender, EventArgs e)
        {
            //  空判断
            if (String.IsNullOrEmpty(this.textBox工艺名称.Text))
            {
                MessageBox.Show("名称不能为空");
                return;
            }
            //  相似判断
            if (!this.if相似判断) {
                //  相似判断
                this.craftDesignDTOs = 款式迭代Service.getRelevantCraftDesignDTOByDesc(this.textBox工艺名称.Text.Trim());
                this.gridControl相似工艺.DataSource = this.craftDesignDTOs;
                this.gridView相似工艺.RefreshData();
                if (this.craftDesignDTOs.Count > 0)
                {
                    MessageBox.Show("存在相似的工艺设计，请确认");
                    this.if相似判断 = true;
                    return;
                }
            }
            //  重复判断
            foreach (CraftDesignDTO craftDesignDTO in this.craftDesignDTOs)
            {
                if (this.textBox工艺名称.Text.Trim().Equals(craftDesignDTO.desc))
                {
                    MessageBox.Show("知识库中已存在该工艺设计，不能重复添加");
                    this.if相似判断 = false;
                    return;
                }
            }
            //  提交  
            CraftDesignDTO craftDesignDto =
                    款式迭代Service.saveCraftDesignDTO(
                        new CraftDesignDTO(
                            this.textBox工艺名称.Text.Trim(),
                            craftDesignItemDTOs
                            )
                        );
            this.Close();
        }
    }
}